﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ZhimeiSoft.Framework.Client.Utils;
using ZhimeiSoft.Framework.Client.Base;
using ZhimeiSoft.CharmManager.DOL;
using ZhimeiSoft.CharmManager.Client.Manager;
using ZhimeiSoft.CharmManager.Client.Interface;


namespace ZhimeiSoft.CharmManager.Client.Forms
{
    public partial class CustomAnalyze : BaseUserControl
    {
        /// <summary>
        /// 员工数据集
        /// </summary>
        private DataSet dsEmployeeInfo = new DataSet();
        /// <summary>
        /// 当前会员信息
        /// </summary>
        private DBEntityCustomInfo customInfo = null;
        /// <summary>
        /// 当前会员预约情况
        /// </summary>
        private DataSet dsReservationCustomInfo = new DataSet();

        public CustomAnalyze()
        {
            InitializeComponent();
            customSearch1.onSerchCustom += OnEventSerchCustom;
            dateTimeInput.Value = DateTime.Now;
            string error = "";
            //装载员工数据
            if (BussinessProxyManager.Instance != null)
            {
                BussinessProxyManager.Instance.QueryEmployeeState(string.Empty, out dsEmployeeInfo, out error);
            }
        }

        public CustomAnalyze(DBEntityCustomInfo queryCustomInfo):this()
        {
            
            customInfo = queryCustomInfo;
        }

        private void InitCustomInfo()
        {
            if (customInfo == null)
                return;

            labCustomName.Text = customInfo.CNAME;
            labNickName.Text = customInfo.CNICKNAME;
            labPhoneNbr.Text = customInfo.CMOBILEPHONE;
            labLastTime.Text = customInfo.CLASTREGISTERDATE.ToLongDateString();
        }

        private void OnEventSerchCustom(DataRow drCustomInfo)
        {
            if (drCustomInfo == null)
                return;

            customInfo = new DBEntityCustomInfo(drCustomInfo);
            InitCustomInfo();
        }


        #region 预约情况
        private void btnQuery_Click(object sender, EventArgs e)
        {
            if (customInfo == null)
            {
                MsgBox.MsgInfo("请选择要查询的用户。");
                return;
            }
            if (dateTimeInput.Value == null)
            {
                MsgBox.MsgInfo("请选择正确的时间。");
                return;
            }
            string error = string.Empty;
            if (!BussinessProxyManager.Instance.QueryCustomReservation(customInfo.CUSTOMERID, dateTimeInput.Value.Year, dateTimeInput.Value.Month,
                out dsReservationCustomInfo, out error))
            {
                MsgBox.MsgInfo("查询预约信息错误： \r\n" + error);
                return;
            }
            grdReservationInfo.DataSource = dsReservationCustomInfo.Tables[0];
        }
        #endregion

        #region 已开的疗程卡
        private void QueryBuyCustomServiceItem(int customID)
        {
            string filter = " CUSTOMERID = " + customID.ToString();
            string error = string.Empty;
            DataSet dsCustomServiceItem;
            bool bFlag = BussinessProxyManager.Instance.QueryCustomerServiceItem(filter, out dsCustomServiceItem, out error);
            if (bFlag == false)
            {
                MsgBox.MsgInfo("获取会员服务项目信息失败\r\n" + error);
                return;
            }
            grdCustomBuyServiceItem.DataSource = dsCustomServiceItem;
        }

        private void grvCustomBuyServiceItem_Click(object sender, EventArgs e)
        {
            if (grvCustomBuyServiceItem.FocusedRowHandle < 0)
            {
                return;
            }
            DataRow drCustomServiceItem = grvCustomBuyServiceItem.GetDataRow(grvCustomBuyServiceItem.FocusedRowHandle);
            int customServiceItemID = Convert.ToInt32(drCustomServiceItem[DBEntityCustomerServiceItem.FieldName.CUSTOMERSERVICEITEMID]);
            DataSet dsCustomServiceItem;
            string error = string.Empty;
            if (!BussinessProxyManager.Instance.QueryCustomServiceItemConsume(customServiceItemID, out dsCustomServiceItem, out error))
            {
                MsgBox.MsgInfo(error);
                return;
            }
            
            
        }
        #endregion

        

        #region 未开的疗程卡

        private void QueryUnBuyCustomServiceItem(int customID)
        {

        }

        #endregion
    }
}
